package common

import (
	"Project/global"
	"Project/model/common/request"
	"Project/model/common/response"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"log"
)

type LoginApi struct{}

// Login 创建用户,包括自身和县区用户
func (s *LoginApi) Login(c *gin.Context) {
	loginRes := request.LoginRes{}
	if err := c.ShouldBind(&loginRes); err != nil {
		global.GVA_LOG.Debug("loginRes", zap.Any("loginRes", loginRes))
		global.GVA_LOG.Debug("loginRes", zap.Error(err))
		response.FailWithMessage("绑定参数失败", c)
		return
	}
	global.GVA_LOG.Debug("loginRes", zap.Any("loginRes", loginRes))
	data, err := loginService.Login(loginRes, c)
	if err != nil {
		log.Println("登录失败", err)
		response.FailWithMessage("登录失败", c)
		return
	}
	response.OkWithDetailed(data, "登录成功", c)
}
